#include "svdpi.h"
#include "common.h"
#include "counter.h"

static std::vector<Counter *> perf_counters;
static int perf_counter_id = 0;
extern "C" void perf_event_accumulate(int id, int inc)
{
    if (id == 0)
        return;
    auto perf_counter = perf_counters[id - 1];
    *perf_counter = *perf_counter + inc;
}
extern "C" int perf_event_reset(int id, const char *name)
{
    if (id == 0)
    {
        perf_counters.push_back(new Counter(name));
        perf_counter_id++;
        LOG("PerfCounter[%d] %s created", perf_counter_id, name);
        return perf_counter_id;
    }
    else
    {
        auto perf_counter = perf_counters[id - 1];
        *perf_counter = 0;
        return id;
    }
}